package pkg_entity;

import java.awt.Rectangle;

public abstract class Entity {
	protected float x;
	protected float y;
	protected Sprite sprite;
	protected float dx; //x Geschwindigkeit
	protected float dy; //y Geschwindigkeit
	protected Rectangle me = new Rectangle();
	protected Rectangle him = new Rectangle();
	
	protected Entity(Sprite sprite, int x, int y) {
		this.sprite = sprite;
		this.x = x;
		this.y = y;
	}
	
	public void move(long delta) {
		x += (delta * dx) / 1000;
		y += (delta * dy) / 1000;
	}
	
	public void setHorizontalSpeed(float dx) {
		this.dx = dx;
	}
	
	public void setVerticalSpeed(float dy) {
		this.dy = dy;
	}
	
	public float getHorizontalSpeed() {
		return dx;
	}
	
	public float getVerticalSpeed() {
		return dy;
	}
	
	public boolean collidesWith(Entity other) {
		me.setBounds((int) x, (int) y, sprite.getWidth(), sprite.getHeight());
		him.setBounds((int) other.x, (int) other.y, other.sprite.getWidth(), other.sprite.getHeight());
		
		return me.intersects(him);
	}
	
	public abstract void collidedWith(Entity other);
}